#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <xip_bytesGeneric.h>
long xip_fixlenReadLong(unsigned char *entrada)
{
 long a=0;
 switch (xip_bytesEndian())
  {
   case XIP_BYTE_LITTLE_ENDIAN:
     printf("Esto es little\n");
     a =  entrada[0];
     a = (a <<8 ) + entrada[1];
     a = (a <<8 ) + entrada[2];
     a = (a <<8 ) + entrada[3];
     break;
   case   XIP_BYTE_BIG_ENDIAN:
     memcpy(&a,entrada,4);
     break;
   default:
     break;
     // no default
  }
 return(a);
}

unsigned xip_fixlenReadUnsigned(unsigned char *entrada)
{
 unsigned x=0;
 switch (xip_bytesEndian())
  {
   case XIP_BYTE_LITTLE_ENDIAN:
    x = entrada[0];
    x = (x <<8 ) + entrada[1];
    break;
   case   XIP_BYTE_BIG_ENDIAN:
     memcpy(&x,entrada,2);
     break;
   default:
     break;
     // no default
  }

 return(x);
}
unsigned char *xip_fixlenWriteLong(unsigned char *buf,long dato)
{
memset(buf,0,4);
unsigned char *pun;
pun= (unsigned char *) &dato;
 switch (xip_bytesEndian())
  {
   case XIP_BYTE_LITTLE_ENDIAN:
     buf[0]=pun[3];
     buf[1]=pun[2];
     buf[2]=pun[1];
     buf[3]=pun[0];
     break;
   case   XIP_BYTE_BIG_ENDIAN:
     memcpy(buf,pun,4);
     break;
   default:
     break;
     // no default
  }
return(buf);
}
unsigned char *xip_fixlenWriteUnsigned(unsigned char *buf,unsigned dato)
{
memset(buf,0,2);
unsigned char *pun;
pun= (unsigned char *) &dato;
 switch (xip_bytesEndian())
  {
   case XIP_BYTE_LITTLE_ENDIAN:
     buf[0]=pun[1];
     buf[1]=pun[0];
     break;
   case   XIP_BYTE_BIG_ENDIAN:
     memcpy(buf,pun,2);
     break;
   default:
     break;
     // no default
  }
return(buf);
}
